subroutine run(ie, t1, t2, r1, r2,fij, fab, fia, & 
          fae, fmi, fme, iijkl, wmnij, iijka, &
          iabij, iiabj, wmbej, iabci, iabcd, icore, &
          maxcore, escf, eccsd, eccsdt) 
use mod_iop
use mod_size
use mod_orbit
use mod_ioff
implicit none
integer prec2, isd2, igpu2, totgpu2
common/precsoc/prec2, isd2, igpu2, totgpu2
!
integer, intent(inout) :: maxcore
real*8, intent(inout) :: escf, eccsd, eccsdt
real*4, intent(in) :: ie(*), fij(*), fab(*), fia(*)
real*4, intent(in) :: fae(*), fmi(*), fme(*)
real*4, intent(in) :: t1(*), t2(*), r1(*), r2(*)
real*4, intent(in) :: iijka(*), iabij(*), iijkl(*)
real*4, intent(in) :: wmnij(*), wmbej(*)
real*4, intent(in) :: iiabj(*), iabci(*), iabcd(*), icore(*)
real*4, allocatable,device :: ig(:)
!
integer nsize 
integer i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10 
integer i11, i12, i13, i14, i15, i16, i17, i18, i19
integer, external :: irpdso, idsymsoc
!
!prec2=prec; isd2=isd; igpu2=igpu; totgpu2=totgpu
!write(6,*)'totgpu', totgpu, totgpu2
if(prec==8) then 
call load(ie, fij, fab, fia, & 
          iijkl, iijka, iabij, iiabj, iabci, iabcd, &
          icore, escf)
elseif(prec==4) then 
call load_s(ie, fij, fab, fia, & 
          iijkl, iijka, iabij, iiabj, iabci, iabcd, &
          icore, escf)
endif
if(ldebug) then 
  write(6,*)'finished load'
endif
!
igpuabci=0
if(igpuabci==0.or.totgpu==0) then 
  call srccsd(ie, fij, fab, fia,  & 
            iijkl, iijka, iabij, iiabj, iabci, iabcd, &
            t1, t2, r1, r2, fae, fmi, fme, wmnij, wmbej, icore,&
            maxcore, escf, eccsd)
elseif(igpuabci==1.and.totgpu==1) then
  write(6,*)'!!!!!!!!!!'
  write(6,*)'all integrals were stored in GPU'
  if(igpuabcd==0) then 
     write(6,*)'except iabcd'
  endif 
  nsize = igpusize
  allocate(ig(nsize))
  i0  = 1                    !ie
  i1  = i0  + (nva+noa+nvb+nob)*isd   !fij
  i2  = i1  + nifoo*isd       !fab
  i3  = i2  + nifvv*isd       !fia
  i4  = i3  + nifvo*isd       !iijkl
  i5  = i4  + nioi1*isd       !iijka
  i6  = i5  + nioi2*isd       !iabij
  i7  = i6  + nioi3*isd       !iiabj
  i8  = i7  + nioi4*isd       !iabci
  i9  = i8  + nioi5*isd       !t1
  i10 = i9  + nifvo*isd       !t2
  i11 = i10 + nioi3*isd       !r1
  i12 = i11 + nifvo*isd       !r2
  i13 = i12 + nioi3*isd       !fae
  i14 = i13 + nifvv*isd       !fmi
  i15 = i14 + nifoo*isd       !fme 
  i16 = i15 + nifvo*isd       !wmnij 
  i17 = i16 + nioi1*isd       !wmbej 
  i18 = i17 + nioi4*isd       !icore
if(igpuabcd==1) then
  i19 = i18 + nioi6*isd       !icore
else
  i19 = i18
endif
  call myicopy_g(ie,  ig(i0), nva+noa+nvb+nob)
  call myicopy_g(fij, ig(i1), nifoo)
  call myicopy_g(fab, ig(i2), nifvv)
  call myicopy_g(fia, ig(i3), nifvo)
  call myicopy_g(iijkl, ig(i4), nioi1)
  call myicopy_g(iijka, ig(i5), nioi2)
  call myicopy_g(iabij, ig(i6), nioi3)
  call myicopy_g(iiabj, ig(i7), nioi4)
  call myicopy_g(iabci, ig(i8), nioi5)
if(igpuabcd==1) then
  call myicopy_g(iabcd, ig(i18), nioi6)
endif
  write(6,*)'begin calculation in gpu'
  call srccsdg(ig(i0), ig(i1), ig(i2), ig(i3),  & 
            ig(i4), ig(i5), ig(i6), ig(i7), ig(i8),  &
            ig(i9), ig(i10), ig(i11), ig(i12), ig(i13), ig(i14), ig(i15),&
            ig(i16), ig(i17), ig(i18), ig(i19),&
            maxcore, escf, eccsd, r1, r2, t1, t2, iabcd, icore)
endif  
 
! call srccsdsect(ie, fij, fab, fia,  & 
!           iijkl, iijka, iabij, iiabj, iabci, iabcd, &
!           t1, t2, r1, r2, fae, fmi, fme, wmnij, wmbej, icore,&
!           t12, t22, r12, r22, icore2, &
!           escf, maxcore)
return
end 
